package config

import (
	"go.mongodb.org/mongo-driver/mongo"
	"go.mongodb.org/mongo-driver/mongo/options"
	"miners-monitor/models/common"
)

type ConfigAoModel struct {
	common.BaseModel
	CommonFunc common.CommonFunc
	ConfigDb   ConfigDbModel
}

func (this *ConfigAoModel) FindOne(filter Config, opts *options.FindOneOptions) Config {
	mongoResult := this.ConfigDb.FindOne(filter, opts)
	result := Config{}
	err := mongoResult.Decode(&result)
	if err == mongo.ErrNoDocuments {
		return Config{}
	} else if err != nil {
		panic(err)
	}
	return result
}

func (this *ConfigAoModel) Upsert(update Config) {
	this.ConfigDb.Upsert(update)
}
